﻿//
//  ProblemSet
//
//  Created by Codyo on 2008-07-05.
//  Copyright (c) 2008 Codyo. All rights reserved.
//



class com.codyo.data.ProblemSet{

	private var data_array:Array = new Array();
	private var distractors:Object = new Object();

	function ProblemSet(){
		
	}
	
	public static function addData(theVerb:String, theNoun:String){
		//creates an array of objects that will populate the question
		var item = data_array.push({verb:theVerb, noun:theNoun});
		trace("data_array[#] = {"+data_array[item].verb+", "+data_array[item].noun+"}");
	}
	
	public function retrieveData(item):Object{
		return(data_array[item]);	
	}
	
	public function shuffleData():Void{
		//this is a random exhaustive array shuffle
		//adopted from an old Robert Penner proto.layer51.com post on shuffling arrays
		//http://proto.layer51.com/d.aspx?f=147
		var len:Number = data_array.length;
		for (var i:Number = 0; i < len; i++) {
			var rand = Math.floor(Math.random()*len);
			//swap current index with a random one
			var temp:Object = data_array[i];
			data_array[i] = data_array[rand];
			data_array[rand] = temp;
		}
	}
	
	public static function addDistractor(word:String){
		//creates an object of possible arrays to serve as distractors
		var letter = word.charAt(0);
		if(distractors[letter] == null){
			distractors[letter] = [word]
		} else {
			distractors[letter].push(word)
		}
	}
	
	public function retrieveDistractor(letter:String):String{
		return distractors[letter][random(distractors[letter].length)];
	}

}